package com.hyy.libray.ui.adapter;

import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;


public class CustomViewHolder extends RecyclerView.ViewHolder {


    private SparseArray<View> mViews;

    public View mRootView;

    public CustomViewHolder(View itemView) {
        super(itemView);
        mRootView = itemView;

        mViews = new SparseArray();

    }


    public static CustomViewHolder creatViewHolder(Context context, int resource, ViewGroup parent) {

        View mView = LayoutInflater.from(context).inflate(resource, parent, false);

        CustomViewHolder customViewHolder = new CustomViewHolder(mView);

        return customViewHolder;
    }

    public <VH extends View> VH getView(int resource) {


        View view = mViews.get(resource);

        if (view == null) {
            view = mRootView.findViewById(resource);
            mViews.put(resource, view);
        }

        return (VH) view;
    }
}
